package evolution_superclasses;

import java.util.Arrays;

import misc.not_Legal_Exception;

public abstract class Selection_Protocol {
	private int _poolSize, _selMechanism;
	protected Phenotype[] _adultPool;
	
	public Selection_Protocol(int nr, int poolSize) {
		_selMechanism = nr;
		_poolSize = poolSize;
	}
	
	public int get_poolSize() {
		return _poolSize;
	}
	
	public void set_poolSize(int poolSize) {
		_poolSize = poolSize;
	}
	
	public Phenotype[] get_adultPool() {
		return _adultPool;
	}
	
	public void set_adultPool(Phenotype[] adultPool) {
		_adultPool = adultPool;
	}

	public void selection(Phenotype[] younglings) throws not_Legal_Exception{
		switch (_selMechanism) {
			case 0:
				fullGenerationReplacement(younglings);
				break;
			case 1:
				overproduction(younglings);
				break;
			case 2:
				generationMixing(younglings);
				break;
	
			default:
				throw new not_Legal_Exception("No such selection protocol!");
		}
		Arrays.sort(_adultPool);
	}
	
	protected abstract void fullGenerationReplacement(Phenotype[] younglings);	
	protected abstract void overproduction(Phenotype[] younglings);	
	protected abstract void generationMixing(Phenotype[] younglings);

}
